// https://leetcode-cn.com/problems/valid-palindrome/
class Solution {
public:
    bool is_alpha(char ch) {
        return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
    }

    bool is_digit(char ch) {
        return ch <= '9' && ch >= '0';
    }

    bool isPalindrome(string s) {
        int l = 0, r = s.size() - 1;
        while (l < r) {
            while (l < r && !(is_alpha(s[l]) || is_digit(s[l]))) ++l;
            while (l < r && !(is_alpha(s[r]) || is_digit(s[r]))) --r;
            if (s[l] <= 'Z' && s[l] >= 'A') s[l] += 32;
            if (s[r] <= 'Z' && s[r] >= 'A') s[r] += 32;
            if (s[l] - s[r]) return false;
            --l, --r;
        }
        return true;
    }
};